﻿Imports EIQ_AIモデル作成_1
Imports Tera計算EIQAI

Public Class Tera計算AIMenuF
    Private Sub Tera計算AIMenu_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        著作L.Text = 著作

    End Sub
    Private Sub EIQ_AIモデル作成Bt_Click(sender As Object, e As EventArgs) Handles EIQ_AIモデル作成Bt.Click
        ' Try to load the EIQ_AIモデル作成 assembly and open E0_MenuF form directly
        Dim startup As String = Application.StartupPath
        Dim solutionRoot As String = System.IO.Path.GetFullPath(System.IO.Path.Combine(startup, "..", "..", ".."))
        Dim candidates As String() = {
            System.IO.Path.GetFullPath(System.IO.Path.Combine(solutionRoot, "EIQ_AIモデル作成", "bin", "Debug", "EIQ_AIモデル作成.exe")),
            System.IO.Path.GetFullPath(System.IO.Path.Combine(solutionRoot, "EIQ_AIモデル作成", "bin", "Release", "EIQ_AIモデル作成.exe"))
        }

        Dim exePath As String = Nothing
        Try
            exePath = candidates.FirstOrDefault(Function(p) System.IO.File.Exists(p))
            If String.IsNullOrEmpty(exePath) Then
                MessageBox.Show("EIQ_AIモデル作成 の実行ファイルが見つかりませんでした。ビルドされていることを確認してください。", "起動エラー", MessageBoxButtons.OK, MessageBoxIcon.Error)
                Return
            End If

            Dim asm = System.Reflection.Assembly.LoadFrom(exePath)
            Dim t = asm.GetType("E0_MenuF", False, True)
            If t IsNot Nothing AndAlso GetType(System.Windows.Forms.Form).IsAssignableFrom(t) Then
                Dim formObj = CType(Activator.CreateInstance(t), System.Windows.Forms.Form)
                formObj.Show()
            Else
                ' Fallback: start the external executable
                Dim psi As New System.Diagnostics.ProcessStartInfo(exePath) With {.UseShellExecute = True}
                System.Diagnostics.Process.Start(psi)
            End If
        Catch exLoad As Exception
            ' If loading the assembly fails, fall back to launching the exe
            Try
                Dim psi As New System.Diagnostics.ProcessStartInfo(exePath) With {.UseShellExecute = True}
                System.Diagnostics.Process.Start(psi)
            Catch ex2 As Exception
                Throw
            End Try
        End Try

    End Sub
    Private Sub Tera計算EIQAIBt_Click(sender As Object, e As EventArgs) Handles Tera計算EIQAIBt.Click
        ' モデルデータ設定Fフォームを開く
        Dim form As New Tera計算EIQAIFrom
        form.Tera計算EIQAI_Tc.SelectedTab = form.AI予測計算Tp
        form.Show()
    End Sub

    Private Sub LinkLabel1_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
        Try
            Dim psi As New System.Diagnostics.ProcessStartInfo("https://ai-jp.eiqtera.com/") With {.UseShellExecute = True}
            System.Diagnostics.Process.Start(psi)
            LinkLabel1.LinkVisited = True
        Catch ex As Exception
            MessageBox.Show("リンクを開けませんでした: " & ex.Message, "エラー", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

    Private Sub LinkLabel2_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles LinkLabel2.LinkClicked
        Try
            Dim psi As New System.Diagnostics.ProcessStartInfo("https://ai-jp.eiqtera.com/eiq_ai_model_creation_jp.html") With {.UseShellExecute = True}
            System.Diagnostics.Process.Start(psi)
            LinkLabel2.LinkVisited = True
        Catch ex As Exception
            MessageBox.Show("リンクを開けませんでした: " & ex.Message, "エラー", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

    Private Sub LinkLabel3_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles LinkLabel3.LinkClicked
        Try
            Dim psi As New System.Diagnostics.ProcessStartInfo("https://ai-jp.eiqtera.com/tera_calculation_eiqai_jp.html") With {.UseShellExecute = True}
            System.Diagnostics.Process.Start(psi)
            LinkLabel3.LinkVisited = True
        Catch ex As Exception
            MessageBox.Show("リンクを開けませんでした: " & ex.Message, "エラー", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub
End Class
